package com.cory.boot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.integration.redis.util.RedisLockRegistry;
import com.cory.boot.base.BaseConstants;

/**
 * redis分布式锁 
 * @author xiongcong
 * @date 2023-01-03
 */
@Configuration
public class RedisLockConfig {
    
    @Bean
    public RedisLockRegistry redisLockRegistry(RedisConnectionFactory redisConnectionFactory) {
        //第一个参数redisConnectionFactory
        //第二个参数registryKey，分布式锁前缀，设置为项目名称会好些
        //该构造方法对应的分布式锁，默认有效期是60秒.可以自定义
        return new RedisLockRegistry(redisConnectionFactory, BaseConstants.CACHE_PREFIX + "_Lock", 60 * 60);
//        return new RedisLockRegistry(redisConnectionFactory, BaseConstants.CACHE_PREFIX + "_Lock");
    }
}
